import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
const { t: reader } = useI18n('device.rfidReader.fields');
const { t: common } = useI18n('common');
const fields = {
  deviceName: reader('device_name'),
  serialNumber: reader('serial_number'),
  deviceModel: reader('device_model'),
  current: reader('current'),
  standbyCurrent: reader('standby_current'),
  startingCurrent: reader('starting_current'),
  onlineDuration: reader('online_duration'),
  totalOnlineDuration: reader('total_online_duration'),
  onlineState: reader('online_state'),
  useStatus: reader('use_status'),
  connectWay: reader('connect_way'),
  connectParameters: reader('connect_parameters'),
  image: reader('image'),
  tagType: reader('tag_type'),
  description: reader('description'),
};
//列表数据
export const columns: BasicColumn[] = [
  {
    title: fields.deviceName,
    align: 'center',
    dataIndex: 'deviceName',
    fixed: 'left',
  },
  {
    title: fields.serialNumber,
    align: 'center',
    dataIndex: 'serialNumber',
    fixed: 'left',
  },
  {
    title: fields.deviceModel,
    align: 'center',
    dataIndex: 'deviceModel',
  },
  // {
  //   title: fields.current,
  //   align: 'center',
  //   dataIndex: 'current',
  // },
  // {
  //   title: fields.standbyCurrent,
  //   align: 'center',
  //   width: 120,
  //   dataIndex: 'standbyCurrent',
  // },
  // {
  //   title: fields.startingCurrent,
  //   align: 'center',
  //   width: 120,
  //   dataIndex: 'startingCurrent',
  // },
  {
    title: fields.onlineDuration,
    align: 'center',
    width: 120,
    dataIndex: 'onlineDuration',
  },
  {
    title: fields.totalOnlineDuration,
    align: 'center',
    dataIndex: 'totalOnlineDuration',
  },
  {
    title: fields.onlineState,
    align: 'center',
    dataIndex: 'useStatus',
    customRender({ text }) {
      return render.renderDict(text, 'deviceUseStates');
    },
  },
  {
    title: reader('online_state'),
    align: 'center',
    dataIndex: 'onlineState',
    customRender({ text }) {
      return render.renderDict(text, 'deviceOnlineStates');
    },
  },
  {
    title: fields.connectWay,
    align: 'center',
    width: 120,
    dataIndex: 'connectionMethod',
    customRender({ text }) {
      return render.renderDict(text, 'connectionMethod');
    },
  },
  {
    title: fields.connectParameters,
    align: 'center',
    width: 120,
    dataIndex: 'connectionParameter',
  },
  {
    title: fields.image,
    align: 'center',
    width: 120,
    dataIndex: 'readerImage',
    customRender: ({ text }) => {
      if (text) {
        return render.renderImage({ text, size: 60 });
      }
      return '';
    },
  },
  {
    title: fields.tagType,
    align: 'center',
    width: 120,
    dataIndex: 'supportTagType',
  },
  {
    title: fields.description,
    align: 'center',
    width: 120,
    dataIndex: 'description',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: fields.deviceName,
    field: 'deviceName',
    component: 'JInput',
    colProps: { span: 6 },
    componentProps: { type: 'like' },
  },
  {
    label: fields.serialNumber,
    field: 'serialNumber',
    component: 'JInput',
    colProps: { span: 6 },
    componentProps: { type: 'like' },
  },
  {
    label: fields.onlineState,
    field: 'onlineState',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'deviceOnlineStates',
    },
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: fields.deviceName,
    field: 'deviceName',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + fields.deviceName }];
    },
    colProps: { span: 12 },
  },
  {
    label: fields.serialNumber,
    field: 'serialNumber',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + fields.serialNumber }];
    },
    colProps: { span: 12 },
  },
  {
    label: fields.deviceModel,
    field: 'deviceModel',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + fields.deviceModel }];
    },
    colProps: { span: 12 },
  },

  {
    label: fields.useStatus,
    field: 'useStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'deviceUseStates',
    },
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + fields.useStatus }];
    },
    colProps: { span: 12 },
  },
  // {
  //   label: fields.current,
  //   field: 'current',
  //   component: 'InputNumber',
  //   colProps: { span: 12 },
  // },
  // {
  //   label: fields.standbyCurrent,
  //   field: 'standbyCurrent',
  //   component: 'InputNumber',
  //   colProps: { span: 12 },
  // },
  // {
  //   label: fields.startingCurrent,
  //   field: 'startingCurrent',
  //   component: 'InputNumber',
  //   colProps: { span: 12 },
  // },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: fields.connectWay,
    field: 'connectionMethod',
    component: 'JDictSelectTag',
    componentProps: {
      //字典code配置，比如通过性别字典编码：sex，也可以使用demo,name,id 表名,名称,值的方式
      dictCode: 'connectionMethod',
      //支持radio(单选按钮)、radioButton(单选按钮 btn风格)、select(下拉框)
      type: 'select',
    },
    colProps: { span: 12 },
  },
  {
    label: fields.connectParameters,
    field: 'connectionParameter',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    label: fields.tagType,
    component: 'Input',
    field: 'supportTagType',
    colProps: { span: 12 },
  },
  {
    label: fields.description,
    component: 'Input',
    field: 'description',
    colProps: { span: 12 },
  },
  {
    label: fields.image,
    component: 'JImageUpload',
    field: 'readerImage',
    colProps: { span: 12 },
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
